-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for request tracing via X-Request-ID header #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ensures that `X-Request-ID` is defaulted to a random value, if no `X-Request-ID` is present in the request. * https://stackoverflow.com/questions/25433258/what-is-the-x-request-id-http-header * https://en.wikipedia.org/wiki/List_of_HTTP_header_fields * http://nginx.org/en/docs/http/ngx_http_core_module.html * https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#generate-request-id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some commentary ... 💬
| log_format main '$remote_addr - $remote_user [$time_local] $status ' | ||
| '"$request" $body_bytes_sent "$http_referer" ' | ||
| '"$http_user_agent" "$http_x_forwarded_for"'; | ||
| '"$http_user_agent" "$http_x_forwarded_for" $proxy_x_request_id'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to improve this log format to have a little more information but I think that's best done in another PR. Using the Kubernetes Ingress - Ingress log format as inspiration ...
log_format upstreaminfo
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
'$request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr '
'$upstream_response_length $upstream_response_time $upstream_status $req_id';There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can get behind this 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to improve this log format to have a little more information but I think that's best done in another PR. Using the Kubernetes Ingress - Ingress log format as inspiration ...
Done in #6.
| proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto; | ||
| proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl; | ||
| proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port; | ||
| proxy_set_header X-Request-ID $proxy_x_request_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some apps like Rails with use this as the request_id if the X-Request-ID exists. Else, they generate one. So it's certainly useful to set it here because it will be used upstream. See ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally beat me to this. 🏆

If the
X-Request-IDis passed along, then it's easier to follow the chain of calls upstream. See commits for details. Each commit is an idea.